// cookie操作
export const cookie = {
  get(key) {
    let arr = []
    let reg = new RegExp('(^| )' + key + '=([^;]*)(;|$)')
    // 如果获取到cookie，则直接返回数据
    if (arr = document.cookie.match(reg)) {
      return unescape(arr[2])
    }
    return null
  },
  set(key, value, time) {
    let Days = 30
    let exp = new Date()
    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000)
    document.cookie = key + '=' + escape(value) + ';expires=' + exp.toGMTString()
  },
  remove(key) {
    let exp = new Date()
    exp.setTime(exp.getTime() - 1)
    let cval = cookie.get(key)
    if (cval) {
      document.cookie = name + '=' + cval + ';expires=' + exp.toGMTString()
    }
  }
}